package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.ProceMtr;
import com.ruoyi.mes.service.IProceMtrService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工序原料Controller
 *
 * @author LongAndHao
 * @date 2023-04-04
 */
@Api(tags = "工序原料")
@RestController
@RequestMapping("/mes/mtr")
public class ProceMtrController extends BaseController {
    @Autowired
    private IProceMtrService proceMtrService;

    /**
     * 查询工序原料列表
     */
    @ApiOperation(value = "查询工序原料列表")
    @PreAuthorize("@ss.hasPermi('mes:mtr:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProceMtr proceMtr) {
        startPage();
        List<ProceMtr> list = proceMtrService.selectProceMtrList(proceMtr);
        return getDataTable(list);
    }

    /**
     * 导出工序原料列表
     */
    @ApiOperation(value = "导出工序原料列表")
    @PreAuthorize("@ss.hasPermi('mes:mtr:export')")
    @Log(title = "工序原料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProceMtr proceMtr) {
        List<ProceMtr> list = proceMtrService.selectProceMtrList(proceMtr);
        ExcelUtil<ProceMtr> util = new ExcelUtil<ProceMtr>(ProceMtr.class);
        util.exportExcel(response, list, "工序原料数据");
    }

    /**
     * 获取工序原料详细信息
     */
    @ApiOperation(value = "获取工序原料详细信息")
    @PreAuthorize("@ss.hasPermi('mes:mtr:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(proceMtrService.selectProceMtrById(id));
    }

    /**
     * 新增工序原料
     */
    @ApiOperation(value = "新增工序原料")
    @PreAuthorize("@ss.hasPermi('mes:mtr:add')")
    @Log(title = "工序原料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProceMtr proceMtr) {
        return toAjax(proceMtrService.insertProceMtr(proceMtr));
    }

    /**
     * 修改工序原料
     */
    @ApiOperation(value = "修改工序原料")
    @PreAuthorize("@ss.hasPermi('mes:mtr:edit')")
    @Log(title = "工序原料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProceMtr proceMtr) {
        return toAjax(proceMtrService.updateProceMtr(proceMtr));
    }

    /**
     * 删除工序原料
     */
    @ApiOperation(value = "删除工序原料")
    @PreAuthorize("@ss.hasPermi('mes:mtr:remove')")
    @Log(title = "工序原料", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(proceMtrService.deleteProceMtrByIds(ids));
    }

}
